package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomMessageModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2022/3/20 0:10
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_NEW_MESSAGE_RESP, desc = "跨服留言返回")
public class CrossNewMessageRespCmd extends AbstractCommand {
    private WingRoomProto.NewMessageRespMsg respMsg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = WingRoomProto.NewMessageRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(WingRoomMessageModule.class).restorePreReduceMessageTimes(1);
        if (respMsg.getRet() == 0) {
            player.getModule(WingRoomMessageModule.class).addMessageTimes(1);
        }
        player.getModule(WingRoomMessageModule.class).syncMsg();
        player.sendPacket(ClientProtocol.U_WING_ROOM_NEW_MESSAGE, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
